
public void dockerTemplate(body) {
  podTemplate(
    containers: [containerTemplate(name: 'docker', image: 'docker', command: 'cat', ttyEnabled: true)],
    volumes: [hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock')]
  ) { body.call() }
}

def onemallStages(vlabel, module){
    def icos= "\u26F0" //montain
    def icot= "\u261B" //pointRightBlack +

	node(vlabel) {ansiColor('xterm') {
		stage(icos+'ARTIFACT'){ container('docker'){ 
			task(icot+'docker-img-build')
			echo "docker-img-build"
			unstash "art1"

			// Lad script from library
			def dockerfile = libraryResource 'templates/dockerfiles/java.Dockerfile'
			writeFile file: './java.Dockerfile', text: dockerfile
			
			//TODO cleanWs
			sh "mkdir -p unpack && tar -zxf $module/$module-application/target/$module-application-assembly.tar.gz -C unpack/ "
			sh "pwd && ls -lh && ls -lh unpack/"
			// sh "docker version"
			// sh "docker build -t ss1 -f java.Dockerfile ."
			sh """
				set +x #close dbg by jenkins
				repo=onemall
				# module
				#imgrepo=registry.cn-shenzhen.aliyuncs.com
				#ns=onemall #demo1-app
				#tag=latest
				#target=\$imgrepo/\$ns/\$repo-$module:\$tag
				#set +e
				#source /opt/jk_ws/profile-sec #load key
				#set -e
				#echo "\${DOCKER_REGISTRY_PW_demo1ct}" |docker login --username=\${DOCKER_REGISTRY_USER_demo1ct} --password-stdin \$imgrepo
				#docker build -t \$target -f java.Dockerfile .

				# NOCAHE="--no-cache"
				#red1="\033[31m" && red2="\033[0m"
				#echo -e ">>>==============={{ \${red1}\$target\${red2} }}>>>build:========================================="
				#docker build \$NOCAHE --pull -t \$target --build-arg repo=\$repo --build-arg TAG=\$tag -f java.Dockerfile .
				#echo -e ">>>==============={{ \${red1}\$target\${red2} }}>>>push:========================================="
				#docker push \$target
      """

// public void onemallTemplate(vlabel, pipeCall) { //ERR exist: ok; none-new: got waiting, non pod generated.
//     // podTemplate(showRawYaml: false) { //showRawYaml: false, 
//     podTemplate(label: vlabel, cloud: 'kubernetes', 
// 			containers: [
//               //containerTemplate(name: 'jnlp', image: 'jenkins/jnlp-slave:alpine', args: '${computer.jnlpmac} ${computer.name}'),
// 			  containerTemplate(name: 'jnlp', image: 'registry.cn-shenzhen.aliyuncs.com/k-spe/dvp-jnlp', alwaysPullImage: true, args: '${computer.jnlpmac} ${computer.name}'),
// 			  containerTemplate(name: 'git', image: 'alpine/git', alwaysPullImage: true, command: 'cat', ttyEnabled: true),
// 			  containerTemplate(name: 'maven', image: 'registry.cn-shenzhen.aliyuncs.com/k-spe/dvp-maven', alwaysPullImage: true, command: 'cat', ttyEnabled: true),
//               //containerTemplate(name: 'docker', image: 'registry.cn-shenzhen.aliyuncs.com/k-spe/dvp-docker', alwaysPullImage: true, command: 'cat', ttyEnabled: true),
//               containerTemplate(name: 'docker', image: 'registry.cn-shenzhen.aliyuncs.com/k-spe/dvp-buildah:v4', alwaysPullImage: true, command: 'cat', ttyEnabled: true),
// 			  containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.10.2', command: 'cat', ttyEnabled: true)
// 			],
// 		  //TODO: use new pod, when tpl updated.
//           volumes: [
// 				//hostPathVolume(hostPath: '/root/.kube', mountPath: '/root/.kube'),
// 				//persistentVolumeClaim(claimName: 'jenkins-jk-ci-data', mountPath: '/opt/jk_ci_data') //, readOnly: true
// 				//persistentVolumeClaim(claimName: 'jenkins-shell', mountPath: '/opt/shell'),
// 				// hostPathVolume(hostPath: '/opt/jenkins/shell', mountPath: '/opt/shell'),
				
// 				//no mount in ct-k3s, try tmpfs.
// 				hostPathVolume(hostPath: '/run/buildah_vol/var/lib/containers', mountPath: '/var/lib/containers'),
// 				hostPathVolume(hostPath: '/run/buildah_vol/run/containers', mountPath: '/run/containers'),				
// 				// hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
// 				hostPathVolume(hostPath: '/opt/pod_volume/.m2', mountPath: '/root/.m2'),
// 				hostPathVolume(hostPath: '/opt/pod_volume/ws', mountPath: '/opt/jk_ws')
//             ],
//           imagePullSecrets: [ 'regsecret' ],
//           idleMinutes: 600,
//           annotations: [
// 				podAnnotation(key: "sidecar.istio.io/inject", value: "false")
//            ]
//     ) { pipeCall } //}

// }

def call(module) {
    //SRC+BUILD+ARTIFACT+TPL+NOTIFY
    //res: pkg-build_scritp, Dockerfile
 	// /configure: 从 master 传递给 agent 的环境变量; ver: 1.24.1	

    def prefix="maven-"
    def vlabel = "${prefix}${UUID.randomUUID().toString().substring(0,4)}"
    def utils = new com.gitee.infrastlabs.Utils()
    ret = utils.getEmpSlave("${prefix}")
    echo "ret: $ret"
    if ( ret.length() != 0) {
		vlabel = ret
    }

    // onemallTemplate(vlabel, this.onemallStages(vlabel, module)) //TODO放到方法块内： 无pod时， 不成生成pod